package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbRepairApply;
import com.ruoyi.wb.dto.WbRepairApplyDto;
import com.ruoyi.wb.service.IWbRepairApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 报修申请Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@Api(tags="报修申请信息管理")
@RestController
@RequestMapping("/wb/wbRepairApply")
@Validated
public class WbRepairApplyController extends BaseController {
    @Autowired
    private IWbRepairApplyService wbRepairApplyService;

    /**
     * 查询报修申请列表
     */
    @ApiOperation("查询报修申请列表")
    @GetMapping("/list")
    public TableDataInfo list(WbRepairApplyDto wbRepairApplyDto) {
        List<WbRepairApply> list = wbRepairApplyService.selectWbRepairApplyList(wbRepairApplyDto);
        return getDataTable(list);
    }

    /**
     * 导出报修申请列表
     */
    @ApiOperation("导出报修申请列表")
    @Log(title = "报修申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbRepairApplyDto wbRepairApplyDto) {
        List<WbRepairApply> list = wbRepairApplyService.selectWbRepairApplyList(wbRepairApplyDto);
        ExcelUtil<WbRepairApply> util = new ExcelUtil<WbRepairApply>(WbRepairApply.class);
        util.exportExcel(response, list, "报修申请数据");
    }

    /**
     * 获取报修申请详细信息
     */
    @ApiOperation("获取报修申请详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wbRepairApplyService.selectWbRepairApplyById(id));
    }

    /**
     * 新增报修申请
     */
    @ApiOperation("新增报修申请")
    @Log(title = "报修申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbRepairApply wbRepairApply) {
        return toAjax(wbRepairApplyService.insertWbRepairApply(wbRepairApply));
    }

    /**
     * 修改报修申请
     */
    @ApiOperation("修改报修申请")
    @Log(title = "报修申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbRepairApplyDto wbRepairApplyDto) {
        return toAjax(wbRepairApplyService.updateWbRepairApply(wbRepairApplyDto));
    }

    /**
     * 删除报修申请
     */
    @ApiOperation("删除报修申请")
    @Log(title = "报修申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wbRepairApplyService.deleteWbRepairApplyByIds(ids));
    }

    /**
     * 查询红点
     */
    @GetMapping("/getRedDot")
    public AjaxResult getRedDot(){
        return AjaxResult.success(wbRepairApplyService.getRedDot());
    }

    /**
     * 修改红点  ifMaster =1  师父已读     ifMaster =2   维修记录已读
     */
    @PutMapping("/putRedDot")
    public AjaxResult putRedDot(@RequestBody Map<String,Long> ifMaster){
        return AjaxResult.success(wbRepairApplyService.putRedDot(ifMaster));
    }
}